{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c4f9c952-cb3b-40f1-bfb5-00d9a43a5715",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "%%captur\n",
    "!pip install data-prep-toolkit\n",
    "!pip install 'data-prep-toolkit-transforms[html2parquet]'\n",
    "!pip install pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f9e6610-957e-4132-9137-cf90f9a709f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dpk_html2parquet.transform_python import Html2Parquet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "76469c87-cfd0-4acd-b57f-36edc52018ff",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "06:50:48 INFO - html2parquet parameters are : {'output_format': <html2parquet_output_format.MARKDOWN: 'markdown'>, 'favor_precision': <html2parquet_favor_precision.TRUE: 'True'>, 'favor_recall': <html2parquet_favor_recall.TRUE: 'True'>}\n",
      "06:50:48 INFO - pipeline id pipeline_id\n",
      "06:50:48 INFO - code location None\n",
      "06:50:48 INFO - data factory data_ is using local data access: input_folder - test-data/input output_folder - output\n",
      "06:50:48 INFO - data factory data_ max_files -1, n_sample -1\n",
      "06:50:48 INFO - data factory data_ Not using data sets, checkpointing False, max files -1, random samples -1, files to use ['.html'], files to checkpoint ['.parquet']\n",
      "06:50:48 INFO - orchestrator html2parquet started at 2024-12-11 06:50:48\n",
      "06:50:48 INFO - Number of files is 1, source profile {'max_file_size': 0.33743762969970703, 'min_file_size': 0.33743762969970703, 'total_file_size': 0.33743762969970703}\n",
      "06:50:49 INFO - Completed 1 files (100.0%) in 0.01 min\n",
      "06:50:49 INFO - Done processing 1 files, waiting for flush() completion.\n",
      "06:50:49 INFO - done flushing in 0.0 sec\n",
      "06:50:49 INFO - Completed execution in 0.01 min, execution result 0\n"
     ]
    }
   ],
   "source": [
    "x=Html2Parquet(input_folder= \"test-data/input\", \n",
    "               output_folder= \"output\", \n",
    "               data_files_to_use=['.html']).transform()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e2bee8da-c566-4e45-bca1-354dfd04b0df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>document</th>\n",
       "      <th>contents</th>\n",
       "      <th>document_id</th>\n",
       "      <th>size</th>\n",
       "      <th>date_acquired</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>test1.html</td>\n",
       "      <td>test1.html</td>\n",
       "      <td># Different ways to create Pandas Dataframe\\n\\...</td>\n",
       "      <td>bbc0d952790a15a89054195dcd03903378251716006bb2...</td>\n",
       "      <td>11366</td>\n",
       "      <td>2024-12-11T06:50:48.947729</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        title    document                                           contents  \\\n",
       "0  test1.html  test1.html  # Different ways to create Pandas Dataframe\\n\\...   \n",
       "\n",
       "                                         document_id   size  \\\n",
       "0  bbc0d952790a15a89054195dcd03903378251716006bb2...  11366   \n",
       "\n",
       "                date_acquired  \n",
       "0  2024-12-11T06:50:48.947729  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyarrow.parquet as pq\n",
    "import pandas as pd\n",
    "table = pq.read_table('output/test1.parquet')\n",
    "table.to_pandas()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cde6e37d-c437-490f-8e01-f4f51a123484",
   "metadata": {},
   "outputs": [],
   "source": [
    "table.to_pandas()['contents'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fd0d13b-1ff6-4988-91fb-52c25ba998c8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "587e43ee-7b51-4a9c-8bf2-0a23e309a7ae",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
